package com.aaa.oauth.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
    * 基本用户信息
    */
@Data
@TableName(value = "tb_acc_account")
public class TbAccAccount implements UserDetails, Serializable {
    @TableId(value = "tid", type = IdType.INPUT)
    private String tid;

    /**
     * 手机号
     */
    @TableField(value = "phone")
    private String phone;

    /**
     * 邮件
     */
    @TableField(value = "email")
    private String email;

    /**
     * 密码
     */
    @TableField(value = "password")
    private String password;

    @TableField(value = "create_by")
    private String createBy;

    @TableField(value = "create_date")
    private Date createDate;

    @TableField(value = "update_by")
    private String updateBy;

    @TableField(value = "update_date")
    private Date updateDate;

    @TableField(value = "remark")
    private String remark;

    @TableField(value = "version")
    private Integer version;

    @TableField(value = "state")
    private Integer state;

    public static final String COL_TID = "tid";

    public static final String COL_PHONE = "phone";

    public static final String COL_EMAIL = "email";

    public static final String COL_PASSWORD = "password";

    public static final String COL_CREATE_BY = "create_by";

    public static final String COL_CREATE_DATE = "create_date";

    public static final String COL_UPDATE_BY = "update_by";

    public static final String COL_UPDATE_DATE = "update_date";

    public static final String COL_REMARK = "remark";

    public static final String COL_VERSION = "version";

    public static final String COL_STATE = "state";

    @TableField(exist = false)
    private Collection<? extends GrantedAuthority> authorities;

    // 返回权限信息
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getUsername() {
        return this.getPhone();
    }

    // 账户是否过期:
    @Override
    public boolean isAccountNonExpired() {
        return this.state==1;
    }

    // 账户是否锁定
    @Override
    public boolean isAccountNonLocked() {
        return this.state==1;
    }

    // 凭证(密码)是否过期
    @Override
    public boolean isCredentialsNonExpired() {
        return this.state==1;
    }

    // 账户是否可用
    @Override
    public boolean isEnabled() {
        return this.state==1;
    }
}